<?php $this->_extends('_layouts/default_layout'); ?>
 
<?php $this->_block('contents'); ?>

<a href="<?php echo url('CommonArticle/add'); ?>"> 文章添加 </a>
<?php if ($num > 0): ?>
<form action="<?php echo url('CommonArticle/Remove'); ?>" method="post" name="mainform" enctype="multipart/form-data" >
	<table cellpadding="0" cellspacing="0" width="100%">
		<tbody class="">
			<tr class="tth">
				<td width="10%">选择</td>
				<td width="80%">文章标题</td>
                <td width="*"></td>
			</tr>
			<?php foreach ($articles as $article): ?>
				<tr class="tth">
					<td width="5%"><input type="checkbox" name="checkboxid[]" id="checkboxid" value="<?php echo $article->article_id ?>" /></td>
					<td width="80%"><a href="<?php echo url('CommonArticle/PreviewArticle', array('article_id' => $article->article_id)) ; ?>"><?php echo $article->article_name; ?> </a> </td>
					<td><a href="<?php echo url('CommonArticle/edit', array('article_id' => $article->article_id)) ; ?>">[编辑]</a></td>
				</tr>
			<?php endforeach; ?>	
			<tr>
				<td class="tbutton" colspan="6">
					<input type="button" value="全选" class="btn" name="choseall" id="Name" onclick = "SelectAll()">
					<input type="submit" onclick = "return(CheckFirst())" value="删除" class="btn" name="submit">
				</td>
			</tr>
		</tbody>
	</table>
</form>
<?php $this->_control('pagination', 'my-pagination', array('pagination' => $pagination)); ?>

<script type="text/javascript">
function SelectAll() 
{
	var flg=0;
 	var checkboxs=document.getElementsByName("checkboxid[]");
 	var count=0;
 	for (var j=0; j<checkboxs.length; j++)
 	{
		var e=checkboxs[j];
		if(e.checked)count++;
 	}
 	if(count < checkboxs.length)
 	{
	 	for (var i=0;i<checkboxs.length;i++) 
	 	{
		 	var e=checkboxs[i];
		 	e.checked =1;
		 	flg= true;
	 	}
 	}
 	else 
 	{
		 for (var i=0;i<checkboxs.length;i++) 
		 {
			 var e=checkboxs[i];
		 		e.checked =0;
		 		flg= false;
	 	}
 	}

 	if (flg)
 	{
		document.mainform.choseall.value = "取消";
 	}
 	else
 	{
		document.mainform.choseall.value = "全选";
 	}
}

function CheckFirst()
{
	var count=0;
	var checkboxs=document.getElementsByName("checkboxid[]");
	for (var i=0;i<checkboxs.length;i++)
	{
		var e=checkboxs[i];
		if(e.checked)count++;
	}
	if(count == 0)
	{
		alert('请先选择删除条目'); 
		return false;
	}
	else
	{
        if(!confirm('您确认要删除吗?')) 
            return false;
        else
            return true; 
	}
}
</script>

<?php else: ?>
<a href="<?php echo url('CommonArticle/add'); ?>"> 请添加文章</a>
<?php endif; ?>


<?php $this->_endblock(); ?>
